package com.elead.oa.controller;

import com.elead.oa.common.PageObject;
import com.elead.oa.entity.Employee;
import com.elead.oa.service.employee.IEmployeeService;
import com.elead.oa.vo.EmployAttendanceVo;
import com.elead.oa.vo.EmployDepartmentVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 考勤管理
 * EmployeeController
 * 创建人:xiaozuolin
 * 创建时间：2021年09月29日 10:06:21
 *
 * @version 1.0.0
 */
@RestController
@RequestMapping("/employee")
@Slf4j
@CrossOrigin
@Api(tags = "员工控制层")
public class EmployeeController {

    @Autowired
    private IEmployeeService employeeService;

    /**
     * 根据员工id，联表查询员工考勤记录
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "根据员工id查询考勤表记录",httpMethod = "GET",produces = "application/json",notes = "根据员工id查询考勤表记录")
    @GetMapping("/get_attendance_by_employ_id/{id}")
    public PageObject<EmployAttendanceVo> getAllAttendanceByEmployId(@PathVariable("id") int id) {
        PageObject<EmployAttendanceVo> pageObject = new PageObject<>();
        pageObject.setRecords(employeeService.getAllAttendanceByEmployId(id));
        return pageObject;
    }

    @GetMapping("/get_employ_by_id/{id}")
    @ApiOperation(value = "根据员工id查询员工信息",httpMethod = "GET",produces = "application/json",notes = "根据员工id查询员工信息")
    public EmployDepartmentVo getEmployById(@PathVariable("id") int id){
        return employeeService.getEmployDepartmentVoById(id);
    }


    /**
     * 考勤管理 列表页面
     *
     * @return
     */
    @GetMapping("/list")
    @ApiOperation(value = "查询员工表所有信息",httpMethod = "GET",produces = "application/json",notes = "查询员工表所有信息")
    public List<EmployDepartmentVo> list() {
        return employeeService.employQuery();
    }

    @GetMapping("/add")
    public String add(@RequestBody Employee employee){
        employeeService.save(employee);
        return "ok";
    }

}
